Technote 1188Packages in Mac OS 9By John MontbriandApple Worldwide Developer Technical Support |
CONTENTS
Overview |
This Technote describes how the Finder implements packages in Mac OS 9. Developers interested in creating packages for use in Mac OS 9 can use this document as a guide for creating packages. Mac OS 9 packages offer a simple consolidated experience for the user when interacting with a package in the Finder's windows, while at the same time preventing accidental tampering with a package's required support files. For Mac OS X package compatibility, an additional package specification for Mac OS X will be released as an adjunct to the Mac OS 9 package specification described in this document. Upon release of this additional specification, developers will be able to create packages to be used in either Mac OS 9 or Mac OS X. |
OverviewPackages in Mac OS 9 are not complex. Simply said, a Package in Mac OS 9 is a folder with the 'package bit' set that contains exactly one alias file at the topmost level. Normally, a package will consist of an application and a number of support files organized into sub-directories. There is only one requirement governing the internal organization of packages, and there are no restrictions on how package sub-directories can be named, how package sub-directories must be organized, or what package sub-directories must contain. Figure 1 provides an illustration of a hypothetical package named SimplePlot.
Although requirements for packages in Mac OS 9 are few, figure 1 illustrates the two main requirements for packages: the appropriate Finder flag must be set for the package's folder and exactly one relative alias must be present in the top level of the package's directory hierarchy. The Package FlagThe folder containing the package has bit 13 (for files, the In Mac OS 9, any folder having this bit set is recognized as a package. If this bit is set, and the folder contains exactly one alias at it's top most level, then the Finder will treat the folder as a package. In some circumstances, due to a software problem or a crash, a folder may wind up having the package bit set when infact it is not a package. In this case, the Finder will treat such a folder as a 'damaged package' and its icon will appear as a blank document with the kind string set to 'package'. To correct this problem, there is a utility called "Package First Aid" provided on the Mac OS 9 install CD. The Top Level Alias FileThe package's folder contains exactly one alias file at its topmost level. This alias points to some other file in the package's directory hierarchy; and, it should be a relative alias so that it will remain valid if a package is copied to another volume. In this discussion, the file pointed to by that alias is called the 'package's main file'.
The package's main file governs the behavior of the package in the Finder's windows. For all intents and purposes, the Finder treats the package as if it were a file containing the 'BNDL', 'FREF', icon resources, et cetera found in the package's main file. For example, when a file is dragged over a package's icon, the Finder
will track the drag command exactly as if the file was being dragged over
the package's main file. Referring to Figure 1, say the application SimplePlot's
There are two ways to create the relative alias file required for a package. The first is to manually create an alias file in the Finder using the "Make Alias" command. The second, is to make the appropriate calls to the resource manager Alias Manager in software as shown in Listing 1.
Listing 1. Sample routine for creating a relative alias file. Developers interested in creating an application for automating the creation
of packages will want to employ some method similar to the routine shown
in Figure 1. Other options include using the Finder's 'Make Alias' command
or creating aliases using applescript. The advantage of calling
The Package's Main FileIn the context of the Finder's windows, a package will behave as if it were a file or an application. And, all of the properties of the package's icon are determined by the package's main file. As shown in figure 2, this is the file referred to by the package's top level alias file.
For example, if the package's main file is an application, then the package will look and feel like an application; and, if the package's main file is a document, then the package will look and feel like a document. The package's main file is used by the Finder to determine the majority of the external characteristics of the package. These characteristics include:
In general, a package will have all the same properties as the package's main file. Points where they differ include:
Application packages (package's whose main file is an application) accept drag and drop operations in Finder windows in the same way application files accept drag and drop operations in Finder windows. Here, the acceptance of a drag and drop is governed by the properties of the package's main file, and if a drop is allowed, then the Finder will send the appropriate Apple event to the package's main file. Other Support FilesOne of the key features of packages is the developer's ability to consolidate many support files together with the main application. By taking advantage of this facility, developers can group the files used in a product in a way that both simplifies the user's task of dealing with the product in the Finder's windows and prevents tampering with the arrangement of the support files used in the product.
A package may contain a complex hierarchy of support files, shared libraries, and other types of files used by the application in it's operation. Also, it is not unreasonable to suppose that a package may contain one or more application files that in some way lend to the overall facility provided by the package. In Figure 1, the package contains a number of support files including private shared libraries presumably used by the main application, a number of AppleScript scripts, and a suite of help files. The Optional Open Document Event ParameterApplication packages may receive a open document
In either case, the Finder will not open the items in the way that it
usually does. Instead, the Finder will package the items into an open
document apple event in a Your open document event handler should be designed to handle each of the three different combinations of event parameters it can receive:
In general, the main application's open document event handler should
always look for the optional Package Compatibility NotesPackages cannot be shared in Mac OS 9. The StandardFile dialogs are not aware of packages. As a result, it is possible for users to use these windows to navigate into package folders and either attempt to open documents inside of them or save documents inside of packages. Navigation Services has been updated to recognize packages and it does not allow users to navigate into them (unless specifically directed to do so). |
Special thanks to Pat McClaughry and the Finder Team.
And, thanks to Tim Holmes, Ingrid Kelly, Karl Schlosser (Editor), John C. Signa, and David J. Wright.